1. Field of the Invention
The present invention relates to the field of computer programming and, more particularly, to embedding an interpreter for a programming language within an application written in a different programming language.
2. Description of the Related Art
Computer programs can be coded in any of a variety of different programming languages. Such is the case as each programming language typically is suited for a different type of task or function. For example, Perl, which stands for Practical Extraction and Reporting Language, is particularly well suited for processing and/or manipulating text. Programming languages such as C++ and Java® are object-oriented programming languages that are well suited for developing distributed application programs such as those commonly found on the Internet.
Due to the large number of available programming languages, it can be useful to augment an application written in one programming language with code that is written in a different programming language. One situation in which this may be desirable is the case where an application, written in a first programming language, requires a particular function that has already been solved or made available in a second programming language. For instance, if an application being developed in C++ requires a function that is commonly available in Perl, it can be useful extend the functionality of the C++ application by including the Perl subroutine within the C++ application rather than to recreate and/or rewrite the Perl subroutine in C++.
One technique for incorporating a subroutine within a high level language is to invoke the subroutine as a separate process from within the high level language application. Using this approach, a Perl script, for example, can be launched using a command such as “system( )” in the C++ programming language. The C++ application waits for the called Perl subroutine to complete execution. The exit status of the subroutine is then checked by the C++ application after execution to determine whether the Perl subroutine executed with any errors.
Use of the “system( )” command is one manner of incorporating a subroutine written in one programming language into an application written in a different programming language. This technique is relatively uncomplicated to implement. There are, however, some disadvantages. First, using a separate process to launch the subroutine is expensive in terms of execution time. Second, it is difficult to pass complex values from the application to the subroutine and to return complex values from the subroutine to the application. For these reasons, use of the “system( )” command to call any more than a few subroutines written in programming languages that are disparate from the host application is not practical.
Another technique for executing a subroutine from a host application is to embed an interpreter directly within the host application. For example, a Perl interpreter can be embedded within a C++ application. With this technique, the subroutine runs “in process” with less expense in terms of the computing resources required. There are, however, many different ways of embedding an interpreter within a host application. If the interactions between the host application and the subroutine are not complicated, embedding the interpreter typically is not difficult. If, however, the interactions between the host application and the subroutine are more involved, this technique can become a very complex endeavor.
It would be beneficial to provide a technique for accessing, from a host application, a subroutine written in a programming language that is different from that of the host application in a manner which overcomes the limitations described above.